home *** CD-ROM | disk | FTP | other *** search
/ PCMania 75 / PCMania CD75_1.iso / lycos / netscape / netcast.z / ncjs10.jar / layermgr.js < prev    next >
Text File  |  1997-11-26  |  4KB  |  195 lines

  1. /* layermgr.js
  2.  
  3.    Copyright (c) 1997 Netscape Comunications Corporation,
  4.    All Rights Reserved
  5.  
  6.    Handles layer management in an efficient way
  7.    
  8. */
  9.  
  10. function LayerLoadObject(layerObj, url, container, notifier, parameter, external)
  11. {
  12.     this.layerObj = layerObj;
  13.     this.layerURL = url;
  14.     this.container = container;
  15.     this.notifier = notifier;
  16.     this.parameter = parameter
  17.     this.nextLoad = null;
  18.     this.external = external;
  19. }
  20.  
  21.  
  22. function LayerMgr_NewLayerAndLoad(layerObj, layerLoadObject) {
  23.     
  24.     layerLoadObject.layerObj = layerObj;
  25.     
  26.     window.layerManager.layerLoad(layerLoadObject);
  27.     
  28.     return;
  29. }
  30.  
  31. function LayerMgr_LayerLoad(layerLoadObject)
  32. {
  33.     
  34.     if (this.mgrBusy == true) {
  35.         setTimeout(this.layerLoad, 100, layerLoadObject);
  36.     }
  37.     
  38.     this.mgrBusy = true;
  39.     
  40.     if ((!this.lastLoad) || (this.lastLoad == null)) {
  41.         
  42.         this.loading = layerLoadObject;
  43.         this.lastLoad = layerLoadObject;
  44.  
  45.         this.mgrBusy = false;
  46.  
  47.         this.startLoad();
  48.     } else {
  49.  
  50.         this.lastLoad.nextLoad = layerLoadObject;
  51.         this.lastLoad = layerLoadObject;
  52.         this.mgrBusy = false;
  53.     }
  54.     
  55.     return; 
  56. }
  57.  
  58. function LayerMgr_StartNextLoad()
  59. {
  60.     var loadObject = this.loading;
  61.     
  62.     if (loadObject && (loadObject != null)) {
  63.         if (this.isLoading == true) {
  64.             java.lang.System.out.println("Warning: another layer is already loading");
  65.         }
  66.         
  67.         this.isLoading = true;
  68.         
  69.         if (loadObject.layerObj == null) {
  70.             var newLayer = this.layerNew(200, loadObject.container);
  71.             
  72.             if (loadObject.layerURL != null) {
  73.                 window.layerManager.loading.layerObj = newLayer;;
  74.                 newLayer.visibility = "show";
  75.                 newLayer.src = loadObject.layerURL;
  76.                 if(loadObject.external == true) {
  77.                     newLayer.__parent__ = null;
  78.                     newLayer.initStandardObjects();
  79.                     newLayer.Event = Event;
  80.                 }
  81.             }
  82.         } else {
  83.             loadObject.visibility = "show";
  84.             loadObject.layerObj.src = loadObject.layerURL;
  85.             if(loadObject.external == true) {
  86.                 loadObject.layerObj.__parent__ = null;
  87.                 loadObject.layerObj.initStandardObjects();
  88.                 loadObject.layerObj.Event = Event;
  89.             }
  90.         }
  91.  
  92.         this.isLoading = false;
  93.     }
  94.     
  95. }
  96.  
  97.  
  98. function LayerMgr_CaptureLoad(e)
  99. {
  100.     var currentLoad = window.layerManager.loading;
  101.     
  102.     if (currentLoad && (currentLoad != null)) {
  103.         if (currentLoad.layerObj != e.target) {
  104.             if (e.target != window) {
  105.                 window.routeEvent(e);
  106.             } else {
  107.                 if (window.onLoadHandler && (window.onLoadHandler != null)) {
  108.                     window.onLoadHandler(e);
  109.                 }
  110.             }
  111.             return;
  112.         }
  113.         
  114.         if (currentLoad.notifier != null && currentLoad.notifier.layerLoaded) {
  115.             currentLoad.notifier.layerLoaded(e.target, currentLoad.parameter);
  116.         }    
  117.  
  118.         window.layerManager.loading = window.layerManager.loading.nextLoad;
  119.         if (window.layerManager.loading == null) {
  120.             window.layerManager.lastLoad = null;
  121.         }
  122.     }        
  123.  
  124.     if (e.target != window) {
  125.         window.routeEvent(e);
  126.  
  127.     } else {
  128.         if (window.onLoadHandler && (window.onLoadHandler != null)) {
  129.             window.onLoadHandler(e);
  130.         }
  131.     }
  132.     
  133.     window.layerManager.startLoad();
  134.         
  135.  
  136. }
  137.  
  138. function LayerMgr_NewLayer(width, parent)
  139. {
  140.     var        returnLayer;
  141.     var     count;
  142.     
  143.     count = this.layerCount--;
  144.     
  145.     if (count > 0) {
  146.         returnLayer = this.layerArray[count];
  147.     } else {
  148.         this.layerCount++;
  149.         returnLayer = new Layer(width, parent);
  150.     }
  151.  
  152.     return returnLayer;
  153. }
  154.  
  155. function LayerMgr_DeleteLayer(thisLayer)
  156. {
  157.     if (thisLayer && thisLayer != null) {
  158.         thisLayer.src="about:blank";
  159.  
  160.         var count = this.layerCount++;
  161.  
  162.         this.layerArray[count] = thisLayer;
  163.     }
  164.  
  165.     return;
  166. }
  167.  
  168. function LayerManager() {
  169.     this.layerCount = 0;
  170.     this.layerArray = new Array(5);
  171.     
  172.     this.layerDelete = LayerMgr_DeleteLayer;
  173.     this.layerNew = LayerMgr_NewLayer;
  174.  
  175.     this.loading = null;
  176.     this.lastLoad = null;
  177.     
  178.     this.layerLoad = LayerMgr_LayerLoad;
  179.     this.startLoad = LayerMgr_StartNextLoad;
  180.  
  181.     this.mgrBusy = false;
  182.     this.isLoading = false;
  183.  
  184.     netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserWrite"); 
  185.     window.enableExternalCapture();
  186.  
  187.     document.captureEvents(Event.LOAD);
  188.     document.onload = LayerMgr_CaptureLoad;
  189.  
  190.     window.layerManager = this;    
  191. }
  192.  
  193. void(0);
  194.  
  195.